package org.example.myframework.frame.demo.others;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Random;

public class GetUuid {
    public static void main(String[] args) {
        try {
            // 每次调用时生成新的 callback 和 _ 参数
            long timestamp = System.currentTimeMillis(); // 使用当前时间戳
            String callback = "jsonp_" + timestamp; // callback 的值为时间戳
            String urlString = "https://support.finance.sina.cn/service/api/openapi.php/VoteService.getUuid?callback=" 
                               + callback + "&_=" + timestamp;
            
            // 创建 URL 对象
            URL url = new URL(urlString);
            
            // 打开连接
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("GET"); // 设置请求方式
            connection.setRequestProperty("Cache-Control", "no-cache");
            connection.setRequestProperty("Pragma", "no-cache");
            connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36");

            // 发送请求并获取响应
            BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String inputLine;
            StringBuilder response = new StringBuilder();
            
            // 读取返回数据
            while ((inputLine = in.readLine()) != null) {
                response.append(inputLine);
            }
            in.close();
            
            // 输出响应
            System.out.println("Response: " + response.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
